package cn.i7baozh.payment.controller;

import cn.i7baozh.api.entities.CommonResult;
import cn.i7baozh.api.entities.Payment;
import cn.i7baozh.api.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author : baoqi.zhang
 * @date :   2022/4/6 12:24
 */
@Slf4j
@RestController
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment) {
        int result = paymentService.create(payment);
        log.info("create result:{}", result);

        if (result > 0) {
            return new CommonResult(200, "成功");
        } else {
            return new CommonResult(400, "失败");
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult queryById(@PathVariable("id") Long id ) {
        Payment payment = paymentService.getById(id);
        log.info("queryById result:{} 1", payment);
        if (Objects.nonNull(payment)) {
            return new CommonResult(200, "成功", payment);
        } else {
            return new CommonResult(400, "失败");
        }
    }
}
